function plot_gaussian(mu=[0 0], sigma=[1 0 ; 0 3], range=5, step_size=0.1)

subplot_amount = 4;

% fix the label-title overlap in suplot
graphics_toolkit fltk 
close all 

effective_range = (range*2)/step_size;

[x_vec, y_vec] = meshgrid(linspace(-range,range,effective_range),linspace(-range,range,effective_range)); 
z = zeros(effective_range, effective_range);

% filling the z matrix
for x = 1:effective_range
    for y = 1:effective_range
        x_value = x_vec(1, x);
        z(x, y) = mvnpdf([x_value, y_vec(y, 1)], mu, sigma);
    end
end

% plotting contour
subplot(subplot_amount, 1, 1)
contour(x_vec, y_vec, z);
%axis ("auto"); 
xlabel('x');
ylabel('y');
title('Gaussian Contour')

% filling the z2 vector
z2 = zeros(effective_range, 1);

for x = 1:effective_range
    x_value = x_vec(1, x);
    z2(x) = mvnpdf(x_value, mu(1), sigma(1));
end

% plotting marginal distribution over x1
subplot(subplot_amount, 1, 2)
plot(z2)
%axis ("auto"); 
xlabel('x');
ylabel('z');
title('Marginal Distrubution over x1')


% filling z3 matrix with 7 vectors for different constant values of x2
x2 = -3:1:3;
z3 = zeros(effective_range, size(x2, 2));

for i = 1:size(x2, 2)
    for x = 1:effective_range
        x_value = x_vec(1, x);
        z3(x, i) = mvnpdf([x_value, x2(i)], mu, sigma);
    end
end


% plotting distrubution over x1 with constant x2
subplot(subplot_amount, 1, [3 4])

colors = ['b', 'r', 'g', 'k', 'm', 'c', 'y'];

for i = 1:size(x2, 2)
    hold on;
    plot(z3(:, i), colors(8-i))
end

legend('-3', '-2', '-1', '0', '1', '2', '3');

%axis ("auto"); 
xlabel('x');
ylabel('y');
title('Distribution over x1 with different values for x2')


% printin' to file!
print ('-dpdf','gaussianContourOne.pdf') 


